﻿/**
 * 
 */
package Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Order;
import service.orderService;
import util.BaseServlet;


public class OrderServlet extends BaseServlet{
	private orderService orderservice = new orderService();
	
	/*public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
		String method = request.getParameter("method");
		if(method.equals("payForOrder")) {
			payForOrder(request, response);
		}
		else if(method.equals("displayOrder")) {
			displayOrder(request, response);
		}
		
	}
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
		doGet(request,response);
	}*/
	public void payForOrder(HttpServletRequest request,HttpServletResponse response) {
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		String bid = request.getParameter("bid");
		boolean result = orderservice.payForOrderService(id, bid);
		if(result) {
			session.setAttribute("msg","付款成功");
		}
		else {
			session.setAttribute("msg", "付款失败");
		}
		try {
			response.sendRedirect(request.getContextPath() + "/cart?method=displayCart");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void displayOrder(HttpServletRequest request,HttpServletResponse response) {
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		Order[] order = null;
		order = orderservice.displayOrderService(id);
		session.setAttribute("bookorder", order);
		try {
			response.sendRedirect(request.getContextPath() + "/displayorder.jsp");
		} catch (IOException e) {
			e.printStackTrace();
		}	
		
		
		
	}
}
